home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Wonky Flux Batch 2019 02
/
Wonky_Flux_Batch_2019-02.zip
/
Wonky Flux Batch 2019-02
/
089 - Misc Stuff - PD.dsk
/
KEYMAC.S
< prev
next >
Wrap
Text File
|
2019-02-17
|
9KB
|
323 lines
********************************
* *
* KEYMAC *
* *
* Examples of uses of MERLIN's *
* add/edit keyboard hooks at *
* $AE-$AF. *
* *
* Glen E. Bredon 3/27/82 *
*------------------------------*
* To use: BRUN desired program *
* from EXEC then invoke with *
* USER from editor. *
********************************
TR
EXP OFF
SAVOBJ KBD ;Save object?
PROGNUM KBD ;Specify 1-5
ERR PROGNUM-1/4
INVEC = $AE ;Edit mode key input vector
EFLG = $F0 ;Minus when in edit mode
AMPER = $3F5
STRINGS = $860 ;Editor puts string here
KEY = $C000
STROBE = $C010
BELL = $FF3A
DO 0
STADR MAC
LDA #]1
STA ]2
LDA #>]1
STA ]2+1
<<<
FIN
********************************
*
* Common code to all parts:
ORG $2F0
LDA #$4C ;Set up USER vector
STA AMPER
>>> STADR.START;AMPER+1
RTS ;End of common stuff
ERR $300-* ;This must ORG at least $300
PAG
********************************
*
* Example 1 (Keyboard macros)
*
* With ESC lead in, prints a *
* followed by 31 copies of chr
* typed after ESC. If this is a
* space then another * is put at
* the end. The cursor is then
* placed on the first character.
*
********************************
DO PROGNUM-1
ELSE
START >>> STADR.INPUT;INVEC
SETSTT SEC
ROR STATE ;Init STATE
RTS
INPUT BIT STATE ;Macro in effect?
BPL NXSTATE ;Branch if so
FRSTKEY LDA KEY ;Otherwise, get key
BPL FRSTKEY
BIT STROBE
CMP #$9B ;ESC lead in?
BEQ NXK ;Branch if so
RTS ;Return with key if not
NXK LDA KEY ;Get key after leadin
BPL NXK
BIT STROBE
CMP #" " ;Control chr?
BLT SETSTT ;Abort if so
STA CHARAC ;Save next chr
LDA #31 ;Init count
STA STATE
AST LDA #"*" ;Send initial *
RTS
NXSTATE LDA CHARAC ;Get chr
DEC STATE ;Countdown
BNE PLUS? ;Last count if equal
CMP #" " ;Was chr a space?
BEQ AST ;Substitue * for last if so
RTS
PLUS? BPL BACK ;Branch if not done
LDA #$9F&"B" ;Put cursor on 1st chr
BACK RTS
STATE BRK
CHARAC BRK
DO SAVOBJ
SAVE REPEAT
FIN
FIN
PAG
***********************************
*
* Example 2 (Keyboard macros)
*
* Keyboard macros defined for keys
* * > " ' # + X Y L S - O C A E
* with the shifted ones equivalent
* to their unshifted counterparts.
*
* Most of these are variants of
* the indirect, indexed by Y
* opcodes, exiting in insert mode
* between the parentheses.
*
***********************************
DO PROGNUM-2
ELSE
STATE = $60 ;Must use zero page
XSAV = $61 ;locations to keep
INDEX = $62 ;program within bounds
START >>> STADR.INPUT;INVEC
LSR STATE ;Init STATE
RTS
INPUT STX XSAV ;Must preserve X (& Y)
BIT STATE ; if used.
BMI GETINDEX ;Branch if doing macro
FRSTKEY JSR GETKEY ;Otherwise, get key
CMP #$9B ;ESC lead in?
BNE EXIT ;Exit if not
NXK JSR GETKEY ;Get key after lead in
CMP #"0" ;Shift chr?
BGE NOOR
ORA #%00010000 ;Shift down
NOOR STA ENDTBL ;In case cmd not found
AND #$7F ; save current input
STA ENDTBL+1 ; to use for it
LDX #0
CMD? LDA MACTBL,X ;Look for command
CMP ENDTBL ;Match input?
BEQ GOTMAC ;Branch if so
GETCHR INX ;Move to next mac
LDA MACTBL,X
BMI GETCHR ;Loop till plus
INX ;Point to cmd byte
BNE CMD? ;Always taken
GOTMAC INX ;Point to macro selected
SXI STX INDEX
GETINDEX LDX INDEX ;Get index to current chr
INC INDEX ;Point to next chr
LDA MACTBL,X ;Get current chr of macro.
TAX ;In case it is WNDUP-MACTBL
CMP #WNDUP-MACTBL ;Is it windup mac?
BEQ SXI ;Branch if so
STA STATE ;Clear flag on last chr
ORA #$80 ;Must always set high bit
EXIT LDX XSAV
RTS
GETKEY LDA KEY
BPL GETKEY
BIT STROBE
RTS
MACTBL
DCI ":**********"
DCI "> >>> "
ASC !2 ASC ""!
DFB $88,$1F&"I" ;Backspace & insert
ASC "7 ASC ''"
DFB $88,$1F&"I"
DCI "3 LDA #"
DCI "X LDX #"
DCI "Y LDY #"
ASC " ; ADC"
DFB WNDUP-MACTBL
ASC "L LDA"
DFB WNDUP-MACTBL
ASC "S STA"
DFB WNDUP-MACTBL
ASC "= SBC"
DFB WNDUP-MACTBL
ASC "O ORA"
DFB WNDUP-MACTBL
ASC "C CMP"
DFB WNDUP-MACTBL
ASC "A AND"
DFB WNDUP-MACTBL
ASC "E EOR"
WNDUP ASC " (),Y"
HEX 888888 ;Backspace to between ()
DFB $1F&"I" ;Exit in insert mode
ENDTBL DA 0 ;Command chr put here
ERR *-1/$3D0
DO SAVOBJ
SAVE KEYMAC
FIN
FIN
PAG
*****************************************
*
* Example 3 (Auto-edit)
*
* USER"string" establishes an auto-edit
* string which will be executed on each
* line of a subsequent Edit. An Add/Insert
* will disconnect the routine.
*
* E.g., if "string" is the sequence
* control O, control J then
* control J will be inserted at the
* start of each line of the edit range.
*
* Control R followed by > or < give the
* effect during the auto edit of the
* arrow keys -> and <-.
*****************************************
DO PROGNUM-3
ELSE
START LDY #-1 ;Move string specified
NXB INY ; in USER command
LDA STRINGS,Y
STA AUTOCMD,Y ;(Max length = $20)
BNE NXB
STA INDEX ;Init index to cmd
LDA INVEC+1 ;Is it connected now?
CMP #>AUTOEDIT
BEQ SETVEC ;Skip if so
STA GETKEY+2 ;Save old invector
LDA INVEC
STA GETKEY+1
SETVEC >>> STADR.AUTOEDIT;INVEC
RTS
AUTOEDIT BIT EFLG ;From Add/Insert or edit?
BMI SAVY ;Branch if from edit
LDA GETKEY+1 ;Disconnect ourselves if
STA INVEC ; from an Add or Insert
LDA GETKEY+2
STA INVEC+1
GETKEY JMP $FD0C ;Address changed
SAVY STY YSAV ;Remember Y
LDY INDEX ;Get index to next cmd chr
INC INDEX ;Point to next one
LDA AUTOCMD,Y ;Get next cmd chr
BNE ISQ ;Branch if not last one
STA INDEX ;Init index for next line
LDA #$8D ;Exit with CR
ISQ CMP #"Q"&$9F ;Control Q?
BNE LEADIN
LDY #0
STY INDEX
LEADIN CMP #"R"&$9F ;Control R lead in?
BNE DOCMD ;Branch if not
INC INDEX ;Bump index
LDA AUTOCMD+1,Y
CMP #"<" ;Next chr a <
BNE RAR
LDA #"H"&$9F ;Translate to backspace
RAR CMP #">" ;or >
BNE DOCMD ;Just ignore cntr R if not
LDA #"U"&$9F ;Translate to cntr U
DOCMD LDY YSAV ;Retrieve Y reg
RTS ;Give editor the chr
YSAV BRK
INDEX BRK
AUTOCMD BRK ;Must be before $3B0
ERR *-1/$3B0
DO SAVOBJ
SAVE AUTO EDIT
FIN
FIN
******************************************
*
* Example 4 (Key redefinition)
*
* Translates ESC to control L (case toggle).
* Remember that this works only in Edit/Add
* mode and not in command mode.
******************************************
DO PROGNUM-4
ELSE
START >>> STADR.INPUT;INVEC
RTS
INPUT LDA KEY
BPL INPUT
BIT STROBE
CMP #$9B ;ESC key?
BNE BACK ;Exit if not
LDA #"L"&$9F ;Replace by cntr L
BACK RTS
DO SAVOBJ
SAVE KEY REDEF
FIN
FIN
LST OFF